﻿package
{
	import pl.Game;

	import starling.core.Starling;

	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.events.Event;
	import flash.geom.Rectangle;

	[SWF(backgroundColor="#000000", frameRate="30", width="800", height="600")]
	public class Application extends Sprite
	{
		private var _starling:Starling;

		public function Application()
		{
			addEventListener( Event.ADDED_TO_STAGE, addedToStageHandler, false, 0, true );
		}

		private function addedToStageHandler( event:Event ):void
		{
			init();
		}

		private function init():void
		{
			stage.align = StageAlign.TOP_LEFT;
			stage.scaleMode = StageScaleMode.NO_SCALE;
			stage.addEventListener( Event.RESIZE, onStageResize );
			_starling = new Starling( Game, stage );
			_starling.start();
			_starling.showStatsAt();
			Starling.current.nativeStage.frameRate =  60;
		}

		private function onStageResize( event:Event ):void
		{
			var sw:Number = stage.stageWidth;
			var sh:Number = stage.stageHeight;
			Starling.current.viewPort = new Rectangle( 0, 0, sw, sh );
			Starling.current.stage.stageWidth = sw;
			Starling.current.stage.stageHeight = sh;
		}
	}
}
